<?php

class Form_Categories extends Zend_Form
{

    public function init()
    {
    	$this->setLegend("添加艺术品分类表单：");
    	$id = new Zend_Form_Element_Hidden("id");
        $id->setValue(0);
        $id->setRequired(true);
        $idValidator = new Zend_Validate_Int();
        $id->addValidator($idValidator);
        $this->addElement($id, "id");
        
        
        $parent = new Zend_Form_Element_Select("parent");
        $parent->setValue(0);
        $parent->setLabel("Parent: ");
        $parent->addMultiOption(0, "无（要添加一级分类）");
        $table = new Model_DbTable_ArtworkCategory();
        $levelOneCategories = $table->fetchAll("parent = 0");
        if ($levelOneCategories) {
	        foreach ($levelOneCategories as $levelOneCategory){
	        	$parent->addMultiOption($levelOneCategory->id, $levelOneCategory->name);
	        }
        }
        $parent->setRequired(true);
        $parentValidator = new Zend_Validate_Int();
        $parent->addValidator($parentValidator);
        $this->addElement($parent, "parent");
        
        
        $name = new Zend_Form_Element_Text("name");
        $name->setLabel("Name: ");
        $name->setRequired(true);
        //$nameValidator = new Zend_Validate_Alnum(false);
        //$name->addValidator($nameValidator);
        $this->addElement($name, "name");
        
        
        $submit = new Zend_Form_Element_Submit("submit");
        $this->addElement($submit, "submit");
    }


}

